#include <cstdio>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	string line;
	getline(cin, line);
	int pos = line.find('-');
	string left(&line[0], &line[pos]);
	string right(&line[pos + 1], &line[line.size()]);
	int left_lenght = count(left.begin(), left.end(), ' ') + 1;
	int right_lenght = count(right.begin(), right.end(), ' ') + 1;
	string left_frist = left.substr(0, left.find(' '));
	string right_frist = right.substr(0, right.find(' '));
	if (left == "joker JOKER" ||
		right == "joker JOKER")cout << "joker JOKER" << endl;
	else if (left_lenght == right_lenght) {
		string str("345678910JQKA2jokerJOKER");
		size_t l = str.find(left_frist);
		size_t r = str.find(right_frist);
		if (l > r) {
			cout << left << endl;
		}
		else {
			cout << right << endl;
		}
	}
	else {
		if (left_lenght == 4)cout << left << endl;
		else if (4 == right_lenght)cout << right << endl;
		else cout << "ERROR" << endl;
	}



}

